package com.campus.handler;

import com.campus.exception.AgeIllegalException;
import com.campus.exception.BaseException;
import com.campus.exception.SubjectException;
import com.campus.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BaseException.class)
    public Result exceptionHandle(BaseException e){
        log.info(e.getMessage());
        return Result.error(e.getMessage());
    }



    //@ExceptionHandler(Exception.class) //捕获所有异常
    public Result exceptionHandle(Exception e){
       log.info("操作失败:{}", e.getMessage());
        return Result.error("操作失败");
    }
}
